package cn.elwy.rcp.ui.explorer.handler;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.IHandler;
import org.eclipse.core.commands.IHandlerListener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;

import cn.elwy.common.exception.MsgLevel;
import cn.elwy.common.exception.RunException;
import cn.elwy.rcp.core.model.ui.entity.MsgInfo;
import cn.elwy.rcp.ui.dialog.MsgDialog;
import cn.elwy.rcp.ui.explorer.create.wizard.NewBuilderProjectWizard;
import cn.elwy.rcp.ui.wizard.BaseWizardDialog;

public class DemoHandler implements IHandler {

	@Override
	public void addHandlerListener(IHandlerListener handlerListener) {
	}

	@Override
	public void dispose() {
	}

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		Shell activeShell = HandlerUtil.getActiveShell(event);
		// WizardAreaDialogDemo d = new WizardAreaDialogDemo(activeShell, SWT.TITLE| SWT.RESIZE);
		// d.open();
		// NewBuilderProjectWizard wizard1 = new NewBuilderProjectWizard();
		// WizardArea dialog1 = new WizardArea(activeShell, wizard1);
		// dialog1.open();
		openDialog(activeShell);

		NewBuilderProjectWizard wizard = new NewBuilderProjectWizard();

		BaseWizardDialog d1 = new BaseWizardDialog(activeShell, wizard);
		d1.open();

		// BaseWizardDialog dialog = new BaseWizardDialog(activeShell, wizard, "NewBuilderProjectWizard");
		// // dialog.setPageSize(800, 360);
		// dialog.open();

		return null;
	}

	private void openDialog(Shell parent) {
		// TODO Auto-generated method stub
		MsgInfo msgInfo = new MsgInfo();
		// msgInfo.setWidth(800);
		// msgInfo.setHeight(200);
		msgInfo.setTitle("");
		msgInfo.setAutoClose(true);
		msgInfo.setCustomTitleImage(true);
		msgInfo.setMsgLevel(MsgLevel.ERROR.toString());
		msgInfo.setMessage("nfomsgInfomsgInInfo");
		msgInfo.setDetailMessage(
				"msgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfo");

		MsgDialog.open(parent, msgInfo);

		RunException e = new RunException("errorMessage", new NullPointerException(
				"msgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfo"));

		MsgDialog.open(parent, e);

		MsgDialog.open(parent, " title", e);

		MsgDialog.open(parent, " title", "message", e);

		MsgDialog.open(parent, MsgLevel.CONFIRM, " title", "message");
		MsgDialog.open(parent, MsgLevel.CONFIRM, " title", "message", "detiallll");

		MsgDialog.openError(parent, "message");
		MsgDialog.openError(parent, e);
		MsgDialog.openError(parent, " title", "e  title");

		MsgDialog.openError(parent, " title", e);
		MsgDialog.openError(parent, " title", "mesg", e);

		MsgDialog.openError(parent, " title", "mesg", "eeeeeeeeee");

		MsgDialog.openWarn(parent, " openWarneeeeeeeeee");
		MsgDialog.openWarn(parent, e);

		MsgDialog.openWarn(parent, "tttt", "cccccc");
		MsgDialog.openWarn(parent, "tttt", e);
		MsgDialog.openWarn(parent, "tttt", "cc", e);
		MsgDialog.openWarn(parent, "tttt", "cc", "ddddd");

		MsgDialog.openInformation(parent, "tttt");
		MsgDialog.openInformation(parent, "tttt", "mmm");

		MsgDialog.openConfirm(parent, "tttt", "mmm");

		MsgDialog.openQuestion(parent, "tttt", "mmm");

		MsgDialog.openQuestionWithCancel(parent, "tttt", "mmm");

		// msgInfo = new MsgInfo();
		// msgInfo.setTitle("title...");
		// msgInfo.setWidth(300);
		// msgInfo.setCustomTitleImage(true);
		// msgInfo.setMsgLevel(MsgLevel.INFO);
		// msgInfo.setMessage("nfomsgInfomsgInfomsgInfo");
		// j = new CMsgDialog(activeShell,SWT.DIALOG_TRIM, msgInfo);
		// j.open();
		//
		// msgInfo = new MsgInfo();
		// msgInfo.setWidth(200);
		// msgInfo.setHeight(600);
		// msgInfo.setTitle("");
		// msgInfo.setCustomTitleImage(true);
		// msgInfo.setMessage("InfomsgInfomsgInfomsgInfo");
		// msgInfo.setDetailMessage("msgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfo");
		// msgInfo.setMsgLevel(MsgLevel.QUESTION);
		// j = new CMsgDialog(activeShell, msgInfo);
		// j.open();
		//
		// msgInfo = new MsgInfo();
		// msgInfo.setWidth(200);
		// msgInfo.setHeight(600);
		// msgInfo.setTitle("");
		// msgInfo.setCustomTitleImage(true);
		// msgInfo.setMessage("InfomsgInfomsgInfomsgInfo");
		// msgInfo.setDetailMessage("msgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfo");
		// msgInfo.setMsgLevel(MsgLevel.CONFIRM);
		// j = new CMsgDialog(activeShell, msgInfo);
		// j.open();
		//
		// msgInfo = new MsgInfo();
		// msgInfo.setTitle("tis");
		// msgInfo.setMessage("msgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfomsgInfo");
		// msgInfo.setMsgLevel(MsgLevel.WARN);
		// j = new CMsgDialog(activeShell, msgInfo);
		// j.open();
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

	@Override
	public boolean isHandled() {
		return true;
	}

	@Override
	public void removeHandlerListener(IHandlerListener handlerListener) {

	}

}
